<link type="text/css" href="/admins/js/jquery/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />

<div class="admin_nrtop">
    <div class="ad_search" style="height: 30px;">
        <form action="/admini/express/channel/"  method="get" style="margin:0px;font-size: 16px;" id="form1">
            <div style="margin-left: 10px;">
                <label for="quick">快速查询：</label><input type="text" id="quick" name="quick"  value="<?php echo $this->quick;?>" style="font-size:16px;"/>
                <input type="hidden" id="isShipNo" name="isShipNo" value="<?php echo ($this->isShipNo === "" && $this->isShipNo === null)?"":$this->isShipNo;?>" />
                <input type="hidden" id="agentId" name="agentId" value="<?php echo $this->agentId?$this->agentId:"";?>" />
                <input type="hidden" id="expressId" name="expressId" value="<?php echo $this->expressId?$this->expressId:"";?>" />
                <input type="submit" id="queryButton" value="查询" style="font-size: 16px;"/>
            </div>
        </form>
    </div> 
</div>
<div style="width: 100%;margin-bottom: 20px;">
<div class="biaoge" style="float: left;width:46%;">
    <div class="biaotbody">
        <table>
            <tr>
                <th class="li30">
                    <div class="lileft"><span>&nbsp;&nbsp;渠道名称</span></div>
                </th>
                <th class="li15">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>隶属方式</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php if($this->expressAll){ foreach ($this->expressAll as $epVal) { ?>
                                    <li><a href="javascript:setCondition('expressId',<?php echo $epVal->id; ?>)"><?php echo $epVal->name; ?></a></li>
                                <?php }} ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li15">
                    <div class="lijz"><span>关键值</span></div>
                </th>
                <th class="li10">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>渠道商</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php if($this->acAll){ foreach ($this->acAll as $acVal) { ?>
                                    <li><a href="javascript:setCondition('agentId',<?php echo $acVal->id; ?>)"><?php echo $acVal->name; ?></a></li>
                                <?php }} ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li10">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>是否原单</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <li><a href="javascript:setCondition('isShipNo',1)">是</a></li>
                                <li><a href="javascript:setCondition('isShipNo',0)">否</a></li>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li1105">
                    <div class="lileft" style="margin-left: 20px;"><span>操作</span></div>
                </th>
            </tr>
        </table>
    </div>
    <?php if($this->expressId || $this->agentId || ($this->isShipNo !== "" && $this->isShipNo !== null)){?>
        <div class="xzinfo" style='margin-bottom: 10px;'>
          <ul>
              <?php if($this->expressId){ ?><li><div class="xzinfobox"><span><?php $channelItem = Application_Model_Express::load($this->expressId);echo $channelItem->name;?></span><a href="javascript:removeset('expressId')" title="撤销"><i>撤销</i></a></div></li><?php }?>
              <?php if($this->agentId){ ?><li><div class="xzinfobox"><span><?php $agentIdItem = Application_Model_AgentCompany::load($this->agentId);echo $agentIdItem->name;?></span><a href="javascript:removeset('agentId')" title="撤销"><i>撤销</i></a></div></li><?php }?>
              <?php if($this->isShipNo === "" && $this->isShipNo !== null){}else{ ?><li><div class="xzinfobox"><span><?php echo $this->isShipNo?"原单":"不是原单";?></span><a href="javascript:removeset('isShipNo')" title="撤销"><i>撤销</i></a></div></li><?php }?>
          </ul>
        </div>
     <?php }?>
    <div class="table" style="margin-bottom: 20px;">
        <table>
             <?php  if($this->channelList){ $i = 0;
                foreach ($this->channelList as $Item) { ?> 
                 <tr>
                     <td class="li30">
                         <div class="lileft">
                             <?php echo $Item->Name;?>
                         </div>
                     </td>
                     <td class="li15">
                         <div class="lileft">
                             <?php echo $Item->ExpressName;?>
                         </div>
                     </td>
                     <td class="li15">
                         <div class="lijz">
                             <?php echo $Item->Key;?>
                        </div>
                     </td>
                     <td class="li10">
                         <div class="lileft">
                             <?php echo $Item->AgentCompanyName;?>
                        </div>
                     </td>
                     <td class="li10">
                         <div class="lijz">
                             <?php echo $Item->isShipNo?"是":"否";?>
                        </div>
                     </td>
                     <td class="li1105">
                         <div class="lixlnav">
                             <a class="xlnavxq" href="javascript:void(0);"  name="<?= $Item->id ?>">修改</a>
                             <div class="xlnavlistbox">
                                 <a class="xlnavsj" href="javascript:void(0);"><i></i></a>
                                 <div class="xlnavlist" style="display:none;">
                                     <ul>
                                          <li><a href="javascript:void(0)" class="delchannelbyid" name="<?= $Item->id ?>">删除</a></li>
                                     </ul>
                                 </div>
                             </div>
                         </div>
                     </td>
                 </tr>
                 <?php $i++;
                    if($i == 20){ ?>
                        </table>
                        </div>
                        </div>
                        <div class="biaoge" style="float: left;width:46%;">
                        <div class="biaotbody">
                            <table>
                                <tr>
                                    <th class="li30">
                                        <div class="lileft"><span>&nbsp;&nbsp;渠道名称</span></div>
                                    </th>
                                    <th class="li15">
                                        <div class="lileft"><span>隶属方式</span></div>
                                    </th>
                                    <th class="li15">
                                        <div class="lijz"><span>关键值</span></div>
                                    </th>
                                    <th class="li10">
                                        <div class="lileft"><span>渠道商</span></div>
                                    </th>
                                    <th class="li10">
                                        <div class="lileft"><span>是否原单</span></div>
                                    </th>
                                    <th class="li1105">
                                        <div class="lileft" style="margin-left: 20px;"><span>操作</span></div>
                                    </th>
                                </tr>
                            </table>
                        </div>
                        <div class="table">
                            <table>
                 <?php } ?>
             <?php } }  if(!$this->channelList){
                echo "<font size='4' color='red'>暂无数据</font>";
                }?>   
         </table>
     </div>
 </div>
</div>
<div class="toolbar">
    <div class="qunx">
        <ul>
            <li><a class="anvbotton" href="javascript:void(0)" id="addChannel" name="addChannel"><span>添加渠道</span></a></li>
        </ul>
    </div>
<?php
    echo $this->partial('paging.phtml', array("pages" => $this->channelAll,"pamas"=>"startId=$this->stateId&startZip=$this->startZip&endZip=$this->endZip&agentId=$this->agentId"));        
?>
</div>
<div class="tanchuang" style="display:none;height: 300px;">
    <div class="nui-msgbox">
        <div class="nui-msgbox-hd" id="wayProblem">添加新渠道</div>
        <a class="nui-msgbox-close" title="关闭"><b></b></a>
    </div>
    <div class="wenti_box" id="addChannel_table">
            <div style="margin-left:50px;margin-top: 15px;margin-bottom: 5px;font-size: 14px;">
                <table id="add_table">
                    <tr style="height: 36px;">
                        <td align="right">渠道名称：</td>
                        <td><input type="text" id="name" name="name" value="" style="font-size:16px;"/></td>
                    </tr>
                    <tr style="height: 36px;">
                        <td align="right">隶属方式：</td>
                        <td><select id="expressId" name='expressId' style="font-size:16px;">
                                <?php foreach($this->expressAll as $epVal){ ?>
                                <option value='<?php echo $epVal->Id;?>'><?php echo $epVal->Name;?></option>
                                <?php } ?>
                            </select></td>
                    </tr>
                    <tr style="height: 36px;">
                        <td align="right">关键值：</td>
                        <td><input type="text" id="key" name="key" value="" style="font-size:16px;"/></td>
                    </tr>
                  
                    <tr style="height: 36px;">
                        <td align="right">渠道商：</td>
                        <td><select id="agentId" name='agentId' style="font-size:16px;">
                                <?php foreach($this->acAll as $acVal){ ?>
                                <option value='<?php echo $acVal->Id;?>'><?php echo $acVal->Name;?></option>
                                <?php } ?>
                            </select></td>
                    </tr>
                    <tr style="height: 36px;">
                        <td align="right">是否原单：</td>
                        <td><select id="isShipNo" name='isShipNo' style="font-size:16px;">
                                <option value='1'>是原单</option>
                                <option value='0'>不是原单</option>
                            </select></td>
                    </tr>
                    <tr style="height: 36px;">
                        <td align="center" colspan="4">
                            <input type="hidden" id="channelId" name="channelId" value="" />
                            <input type="button" id="navigationAdd" naem="navigationAdd" value="确定" style="background-color: #F60;width: 50px;height: 36px;color: white;font-size: 16px;border-radius:8px;"/>
                            &nbsp;&nbsp;<input type="button" id="refo" name="refo" class='refo' value="返回" style="background-color: #1668A4;width: 50px;height: 36px;color: white;font-size: 16px;border-radius:8px;"/>
                        </td>
                    </tr>
                </table>
            </div>
    </div>
</div>
<div class="houtai_overlay" style="display:none;"></div>
<script>
    $(".lixiala").click(function(){
        $(".lixiala").attr("class","lixiala");
        $(".lixiala").next("div").attr("style","display:none;");

        $(this).attr("class","lixiala bton");
        $(this).next("div").attr("style","display:block;");
    });
    $(document).bind("click",function(e){
        var target  = $(e.target);
        if(target.closest(".biaoxiala").length == 0){
            $(".lixiala").attr("class","lixiala");
            $(".lixiala").next("div").attr("style","display:none;");
        }
    });
    function setCondition(name,val)
    {
        $("#form1 #"+name).val(val);
        $("#form1").submit();
    }
    function removeset(name)
    {
        $("#form1 #"+name).val("");
        $("#form1").submit();
    }
    $("#addChannel").click(function(){
        $("div.tanchuang").show();
        $("div.houtai_overlay").show();
    });
    $(".nui-msgbox-close,#refo").click(function(){
        $("#addChannel_table #name").val("");
        $("#addChannel_table #key").val("");
        $("#addChannel_table #channelId").val("");
        $("div.tanchuang").hide();
        $("div.houtai_overlay").hide();
    });
    $(".xlnavsj").live("mousemove",function(){
        $(this).next("div").attr("style","display:block;");
    });
    $(".lixlnav").mouseleave(function(){
        $(".xlnavsj").next("div").attr("style","display:none;");
    });
    $(".xlnavxq").click(function(){
        var channelId = $(this).attr("name");
        $.post('/admini/express/channelinfo', {'channelId':channelId}, function(sj){
             if(sj.type == 1){
                $("#addChannel_table #channelId").val(channelId);
                $("#addChannel_table #name").val(sj.name);
                $("#addChannel_table #key").val(sj.key);                
                $("#addChannel_table #expressId").find("option[value='"+sj.expressId+"']").attr("selected",true);
                $("#addChannel_table #agentId").find("option[value='"+sj.agentCompanyId+"']").attr("selected",true);
                $("#addChannel_table #isShipNo").find("option[value='"+sj.isShipNo+"']").attr("selected",true);
                $(".houtai_overlay").show();
                $(".tanchuang").show();
             }else{
                 alert("出现未知错误");
             }
        }, 'json');
    });
    $("#navigationAdd").click(function(){
        var name = $("#addChannel_table #name").val();
        var channelId = $("#addChannel_table #channelId").val();
        var key = $("#addChannel_table #key").val();
        var expressId = $("#addChannel_table #expressId").val();
        var agentId = $("#addChannel_table #agentId").val();
        var isShipNo = $("#addChannel_table #isShipNo").val();
        if(name == ""){
            alert("渠道名称不能为空");
            return false;
        }
        $.post('/admini/express/addoredit', {'channelId':channelId,'name':name,'key':key,'expressId':expressId,'agentId':agentId,'isShipNo':isShipNo}, function(sj){
             if(sj == 1){
                alert("操作成功");
                location.reload();
             }else{
                 alert("出现未知错误");
             }
        }, 'json');
    });
    $(".delchannelbyid").click(function(){
       var channelId = $(this).attr("name");
       $.post('/admini/express/delchannel', {'channelId':channelId}, function(sj){
            if(sj == 1){
                alert("删除成功");
                location.reload();
            }else{
                alert("出现未知错误");
            }
        }, 'json');
    });
</script>